package listener;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

/**
 * 实现了 HttpSessionAttributeListener 接口的类
 * 就是监听 session 对属性相关操作的监听器
 */
public class LmyHttpSessionAttributeListener implements HttpSessionAttributeListener {

    @Override
    public void attributeAdded(HttpSessionBindingEvent se) {
        String name = se.getName();
        System.out.println("LmyHttpSessionAttributeListener 监听到session添加属性 " + se.getName() + "=" + se.getValue());
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent se) {
        HttpSession session = se.getSession();
        System.out.println("LmyHttpSessionAttributeListener 监听到 session移除属性 " + se.getName());
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent se) {
        HttpSession session = se.getSession();
        System.out.println("LmyHttpSessionAttributeListener 监听到 session修改属性 " + se.getName() + "=" + se.getValue());
    }
}
